package com.kingyea.mobilepolice.rolepermission.controller;

import com.kingyea.mobilepolice.rolepermission.bean.RolePermission;
import com.kingyea.mobilepolice.rolepermission.service.RolePermissionService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Mr.Lin
 * @version v1.0.0
 * @description RolePermission 控制层
 * @date Created in 2018-03-30 15:32:07
 */
@RequestMapping(value = "/rolePermission")
@RestController
public class RolePermissionController {

    private static final Logger LOGGER = LoggerFactory.getLogger(RolePermissionController.class);

    @Autowired
    private RolePermissionService rolePermissionService;

    /**
     * 查询全部
     *
     * @param
     * @return
     */
    @RequestMapping(method = RequestMethod.GET)
    public List<RolePermission> list() throws Exception {
        return rolePermissionService.search(null);
    }

    /**
     * 通过ID查找对象
     *
     * @param id
     * @return
     */
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    public RolePermission detail(@PathVariable Integer id) throws Exception {
        return rolePermissionService.getById(id);
    }

    /**
     * 创建
     *
     * @param rolePermission
     * @return
     */
    @RequestMapping(method = RequestMethod.POST)
    public RolePermission create(@RequestBody RolePermission rolePermission) throws Exception {
        return rolePermissionService.save(rolePermission);
    }

    /**
     * 更新
     *
     * @param rolePermission
     * @return
     */
    @RequestMapping(method = RequestMethod.PUT)
    public RolePermission update(@RequestBody RolePermission rolePermission) throws Exception {
        return rolePermissionService.update(rolePermission);
    }

    /**
     * 删除
     *
     * @param id
     * @return
     */
    @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
    public int delete(@PathVariable Integer id) throws Exception {
        return rolePermissionService.deleteById(id);
    }

}
